import FlowGraph from '../../../graph/index'

export function nodeOpt(id, globalGridAttr) {
  let curCel = null
  if (id) {
    const { graph } = FlowGraph
    const cell = graph.getCellById(id)
    if (!cell || !cell.isNode()) {
      return
    }
    curCel = cell
    globalGridAttr.nodeStroke = cell.attr('body/stroke')
    globalGridAttr.nodeStrokeWidth = cell.attr('body/strokeWidth')
    globalGridAttr.nodeFill = cell.attr('body/fill') || 'none'
    globalGridAttr.nodeFontSize = cell.attr('text/fontSize')
    globalGridAttr.nodeFontColor = cell.attr('text/fill')
    globalGridAttr.nodeUsers = cell.attr('approve/users')
    globalGridAttr.nodeWidth = cell.attr('data/width')
    globalGridAttr.nodeHeight = cell.attr('data/height')
    globalGridAttr.nodeAngle = cell.attr('data/angle')
    globalGridAttr.magnet = cell.attr('body/magnet') || false
  }
  return curCel
}
